# -*- coding:utf-8 -*-
# @Time : 2021-11-11 9:53
# @Author : huabao.tan
# @File : send_email.py
# @Software: PyCharm

from pypinyin import lazy_pinyin
import datetime
import random
import openpyxl
import tkinter as tk
from tkinter import filedialog
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font


# 随机生成名字
def create_name():
    head = random.randint(0xb0, 0xf7)
    body = random.randint(0xa1, 0xf9)
    vac = f'{head:x}{body:x}'
    first_name = bytes.fromhex(vac).decode('gb2312')
    head1 = random.randint(0xb0, 0xf7)
    body1 = random.randint(0xa1, 0xf9)
    vaa = f'{head1:x}{body1:x}'
    secound_name = bytes.fromhex(vaa).decode('gb2312')
    head2 = random.randint(0xb0, 0xf7)
    body2 = random.randint(0xb0, 0xf7)
    vab = f'{head2:x}{body2:x}'
    last_name = bytes.fromhex(vab).decode('gb2312')
    name = first_name + secound_name + last_name
    return name


# 随机生成拼音
def spell_name(name):
    a = ""
    b = lazy_pinyin(name)
    for c in b:
        a += c
    return a


# 随机生成手机号码
def generate_phone():
    sec = [3, 4, 5, 7, 8][random.randint(0, 4)]
    th = {
        3: random.randint(0, 9),
        4: [a for a in range(5, 10)][random.randint(0, 4)],
        5: [a for a in range(10) if a != 4][random.randint(0, 7)],
        7: [a for a in range(8)][random.randint(0, 7)],
        8: random.randint(0, 9)
    }[sec]
    end = random.randint(10000000, 99999999)
    phone = '1{0}{1}{2}'.format(sec, th, end)
    return phone


# 随机生成邮箱
def email(name):
    list = ['@mzt.com', '@thb.com', '@lfz.com', '@mcy.com']
    acc = random.choice(list)
    acc = str(acc)
    n = spell_name(name)
    c = ""
    for a in n:
        c += a
    email = c + acc
    return email


# 随机生成性别
def create_sex():
    sex = random.choice('男女')
    return sex


# 随机生成年龄
def create_age():
    age = random.randint(18, 30)
    return str(age)


# 随机生成个人信息
def create_msg():
    name = create_name()
    msg = "名字：" + name + "\n" + "性别：" + create_sex() + "\n" + "年龄：" + create_age() + "岁" + "\n" + "手机号码：" + generate_phone() + "\n" + "邮箱：" + email(
        name)
    return msg


# 生成当前时间
def now_time():
    time = datetime.date.today()
    return time


# 评估关系
def assess():
    list = ['上级', '平级', '下属']
    acc = random.choice(list)
    return acc


# 图形化保存文件
def save_file():
    root = tk.Tk()
    root.withdraw()
    Fpath = filedialog.asksaveasfilename()
    return Fpath


def message():
    print('请先选择文件保存路径：')
    file = save_file()
    min = int(input('请输入被测评者的数量：'))
    max = int(input('请输入测评者的数量：'))
    wb = openpyxl.Workbook()
    fun(min, max, wb)
    wb.save(r'%s.xlsx' % file)
    wb.close()


def fun(n, m, wb):
    alignment = Alignment(horizontal='center', vertical='center')
    # cell.alignment = alignment
    sheet1 = wb.active
    sheet1.column_dimensions['A'].alignment= alignment
    sheet1.column_dimensions['A'].width = 26
    sheet1.column_dimensions['B'].width = 14
    sheet1.column_dimensions['C'].width = 22
    sheet1.column_dimensions['D'].width = 26
    sheet1.column_dimensions['E'].width = 14
    sheet1.column_dimensions['F'].width = 10
    sheet1.title = '人员信息'
    sheet1.append(['*被评估人邮箱', '*被评估人姓名', '*被评估人是否开通自评', '*评估人邮箱', '*评估人姓名', '*评估关系', '手机'])
    i = 0
    while i < n:
        name = create_name()
        e = email(name)
        # p = generate_phone()
        # d = datetime.datetime.now()
        a = 2
        sheet1.cell(row=a + (m + 1) * i, column=1, value=e)
        sheet1.cell(row=a + (m + 1) * i, column=2, value=name)
        sheet1.cell(row=a + (m + 1) * i, column=3, value='是')
        sheet1.cell(row=a + (m + 1) * i, column=4, value=e)
        sheet1.cell(row=a + (m + 1) * i, column=5, value=name)
        sheet1.cell(row=a + (m + 1) * i, column=6, value='自评')
        j = 0
        while j < m:
            b = j + 3
            sheet1.cell(row=b + (m + 1) * i, column=1, value=e)
            sheet1.cell(row=b + (m + 1) * i, column=2, value=name)
            sheet1.cell(row=b + (m + 1) * i, column=3, value='是')
            name1 = create_name()
            e1 = email(name1)
            acc = assess()
            sheet1.cell(row=b + (m + 1) * i, column=4, value=e1)
            sheet1.cell(row=b + (m + 1) * i, column=5, value=name1)
            sheet1.cell(row=b + (m + 1) * i, column=6, value=acc)
            sheet1.cell(row=b + (m + 1) * i, column=3, value='否')
            j += 1
        i += 1


def begin():
    while True:
        message()
        print('正在写入请稍后~~')
        print('---------执行完成---------')
        print('是否继续:')
        res = input('请输入y/n：')
        if res == 'y':
            continue
        else:
            print("谢谢使用")
            break


if __name__ == '__main__':
    begin()

# 打包命令 pyinstaller -F -c +文件名.py
